<?php

/**
 * 
 */
class Login_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function doLogin() {
        $data['login'] = $this->input->post('login');
        $data['password'] = md5($this->input->post('password'));

        $sql = "SELECT user_id,login FROM users
			 WHERE login='" . $data['login'] . "' AND password='" . $data['password'] . "'";
        $query = $this->db->query($sql);
        $array = $query->result_array();
        if ($query->num_rows() == 0) {
            // return "Invalid username or password!";
            $this->session->sess_destroy();
            return FALSE;
            // redirect('/'); 
        } else {
            $this->session->set_userdata('sess_id', TRUE);
            $this->session->set_userdata('sess_user_id', $array[0]['user_id']);
            $this->session->set_userdata('sess_login', $array[0]['login']);
            return TRUE;
        }
        // redirect('/'); 
    }

    public function doLogout() {
        $this->session->sess_destroy();
        redirect('/');
    }

}

?>